﻿//
// 请注意：bbsmax 不是一个免费产品，源代码仅限用于学习，禁止用于商业站点或者其他商业用途
// 如果您要将bbsmax用于商业用途，需要从官方购买商业授权，得到授权后可以基于源代码二次开发
//
// 版权所有 厦门麦斯网络科技有限公司
// 公司网站 www.bbsmax.com
//

using System;
using System.Collections;
using System.Web;

using MaxLabs.WebEngine;
using MaxLabs.bbsMax.Enums;
using MaxLabs.bbsMax.Errors;
using MaxLabs.bbsMax.Rescourses;
using MaxLabs.bbsMax.Entities;
using MaxLabs.bbsMax.StepByStepTasks;
using System.Collections.Generic;


namespace MaxLabs.bbsMax.Web.max_dialogs
{
    public partial class attachment_delete : AdminDialogPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (_Request.IsClick("delete"))
            {
                DeleteAttachment();
            }
        }

        private void DeleteAttachment()
        {
            int? atttachmentID = _Request.Get<int>("attachmentID", Method.Post);
            int? forumID = _Request.Get<int>("forumID", Method.Post);

            bool success = false;
            using (ErrorScope es = new ErrorScope())
            {
                MessageDisplay msgDisplay = CreateMessageDisplay();


                if (atttachmentID == null)
                    msgDisplay.AddError(new InvalidParamError("atttachmentID").Message);

                if (forumID == null)
                    msgDisplay.AddError(new InvalidParamError("forumID").Message);

                if (msgDisplay.HasAnyError())
                    return;

                try
                {
                    success = PostBOV5.Instance.DeleteAttachments(My, forumID.Value, new int[] { atttachmentID.Value });
                }
                catch (Exception ex)
                {
                    msgDisplay.AddException(ex);
                }

                if (success == false)
                {
                    es.CatchError<ErrorInfo>(delegate(ErrorInfo error)
                    {
                        msgDisplay.AddError(error);
                    });
                }
            }

            if (success)
            {
                Return(atttachmentID.Value);
            }
        }
    }
}